p7 <- ggplot(all, aes(x = percentile_2016, y = Current_Asthma2018, size = totalpopE, alpha = 1/10, color = county)) +
geom_point() +
labs(x = "PM2.5 Percentile, 2016", y = "Percent with Asthma")
ggMarginal(p7, type = "histogram")
# adjustments
p7 <- ggplot(all, aes(x = percentile_2016, y = Current_Asthma2018, size = totalpopE, alpha = 1/10, color = county)) +
geom_point() +
labs(x = "PM2.5 Percentile, 2016", y = "Percent with Asthma") +
guides(size = "none", alpha = "none") +
theme(legend.position = "bottom")
ggMarginal(p7, type = "histogram")
ggplotly(p7)
# upper left panel
xhist <- plot_ly(data = all, x = ~percentile_2016, type = 'histogram',
nbinsx = 20, alpha =.75, color = I("grey"))
# lower left panel
xyscatter <- plot_ly(data = all,
x = ~percentile_2016,
y = ~Current_Asthma2018,
type = 'scatter',
mode = 'markers',
marker = list(size = ~totalpopE, sizeref = 20, sizemode = 'area'),
color = ~county,
colors = "Dark2",
alpha = .75,
hoverinfo = 'text',
text = ~paste('County:', county, '<br>Population:', totalpopE,
'<br>PM2.5 Percentile:', percentile_2016,
'<br>Percent with Asthma:', Current_Asthma2018)) %>%
layout(xaxis = list(title = "PM2.5 Percentile, 2016"),
yaxis = list(title = "Percent with Asthma"),
legend = list(orientation = "h", x = 0, y = -0.2))
# lower right panel
yhist <- plot_ly(data = all, y = ~Current_Asthma2018, type = 'histogram',
nbinsx = 20, alpha = .75, color = I("grey"))
Pieces were built separately and assembled with subplot()
# plotly_empty fills in upper right panel with nothing
subplot(xhist, plotly_empty(), xyscatter, yhist,
nrows = 2, heights = c(.2, .8), widths = c(.8,.2), margin = 0,
shareX = TRUE, shareY = TRUE) %>%
style(showlegend = FALSE, traces = c(1,9)) %>% # remove hist symbols from legend
layout(xaxis = list(showgrid = TRUE),
yaxis2 = list(showgrid = TRUE))
How to get the primary box/edges around the scatterplot?